package cn.pupil.design.impl;

import cn.pupil.design.ICalculateArea;

/**
 * @Description: 计算面积实现类
 * @Author: pupil
 * @Date: 2024/06/22 下午 9:28
 */
public class ICalculateAreaImpl implements ICalculateArea {

    private final static double π = 3.14D;

    /**
     * 计算长方形面积
     * @param x
     * @param y
     * @return
     */
    public double rectangle(double x, double y) {
        return x * y;
    }

    /**
     * 计算三角形面积
     * @param x
     * @param y
     * @param z
     * @return
     */
    public double triangle(double x, double y, double z) {
        double p = (x + y + z) / 2;
        return Math.sqrt(p * (p - x) * (p - y) * (p - z));
    }

    /**
     * 计算圆形面积
     * @param r
     * @return
     */
    public double circular(double r) {
        return π * r * r;
    }
}
